package com.wings4.security

class Feature {
    Integer id
    String description
    String documents
    String fields
    String module
    String operation

    static hasMany = [authorities : Authority]

    static belongsTo = [Authority]


    static constraints = {
        description(nullable: true)
        documents(nullable: true)
    }
    public static void initialize(){
        def defaultAuthority = Authority.get(1);
        def defaultUser = User.get(1);
        def academicConfigurationList = new Feature(
                description: "all",
                documents: "all",
                fields: "all",
                module: "academicConfiguration",
                operation: "academicYearJsonData"
        )
        def academicConfigurationList1 = new Feature(
                description: "all",
                documents: "all",
                fields: "all",
                module: "academicConfiguration",
                operation: "academicYearList"
        )
        def admissionList = new Feature(
                description: "all",
                documents: "all",
                fields: "all",
                module: "admission",
                operation: "admissionList"
        )
        def admissionCreate= new Feature(
                description: "all",
                documents: "all",
                fields: "all",
                module: "admission",
                operation: "admissionCreate"
        )
        def admissionSave= new Feature(
                description: "all",
                documents: "all",
                fields: "all",
                module: "admission",
                operation: "admissionSave"
        )
        def admissionEdit= new Feature(
                description: "all",
                documents: "all",
                fields: "all",
                module: "admission",
                operation: "admissionEdit"
        )
        def admissionUpdate= new Feature(
                description: "all",
                documents: "all",
                fields: "all",
                module: "admission",
                operation: "admissionUpdate"
        )
        def admissionJsonData= new Feature(
                description: "all",
                documents: "all",
                fields: "all",
                module: "admission",
                operation: "admissionJsonData"
        )
        def admissionDelete= new Feature(
                description: "all",
                documents: "all",
                fields: "all",
                module: "admission",
                operation: "admissionDelete"
        )
        defaultAuthority.addToFeatures(academicConfigurationList).addToFeatures(academicConfigurationList1).addToFeatures(admissionList).
        addToFeatures(admissionCreate).addToFeatures(admissionSave).addToFeatures(admissionEdit).addToFeatures(admissionUpdate).
               addToFeatures(admissionJsonData).addToFeatures(admissionDelete)
        defaultUser.addToAuthorities(defaultAuthority).save(flush: true);
    }
}
